package com.example.demo.mvc;

import com.example.demo.PlusController;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.web.servlet.RequestBuilder;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;

import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;

/**
 * @Author: Tylan
 * @CreateDate: 2018/7/2 11:11
 * @UpdateDate: 2018/7/2 11:11
 */
public class PlusControllerTest2 extends MockTestBase {
    @InjectMocks
    PlusController plusController;

//    @Mock
//    SomeService someService;

    @Override
    public void setUp() {
        this.mockMvc = MockMvcBuilders.standaloneSetup(plusController).build();
    }

    @Test
    public void insertTestWrongParam() throws Exception {
        /*
        * 测试data为空
        * */
        System.out.println("insertTestWrongParam");
        // 构造测试数据
        String data1 = "";
        String data2 = "";
        String insertUrl = "/plus/add";
        // 执行请求与断言
        RequestBuilder request = MockMvcRequestBuilders.get(insertUrl)
                .requestAttr("a", 2).requestAttr("b", 1);
        mockMvc.perform(request).andDo(print()).andExpect(jsonPath("xxx")
                .value("3"));
    }

    public static void main(String[] args) throws ClassNotFoundException {
        testAll(Thread.currentThread().getStackTrace()[1].getClassName());
    }
}